﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MDIApp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form2 _mdiChild = new Form2();
            _mdiChild.TopLevel = false;
            _mdiChild.MdiParent = this;
            _mdiChild.Show();
        }

        private void casToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.LayoutMdi(MdiLayout.Cascade);
        }

        private void horizontalyTileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.LayoutMdi(MdiLayout.TileHorizontal);
        }

        private void verticalTileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.LayoutMdi(MdiLayout.TileVertical);
        }

        private void copyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form _activeChild = this.ActiveMdiChild;

            if (_activeChild != null)
            { 
                RichTextBox _editBox = (RichTextBox)_activeChild.ActiveControl;

                if (_editBox != null)
                {
                    Clipboard.SetDataObject(_editBox.SelectedText);
                }
            }
        }

        private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form _activeChild = this.ActiveMdiChild;

            if (_activeChild != null)
            {
                RichTextBox _editBox = (RichTextBox)_activeChild.ActiveControl;

                if (_editBox != null)
                {
                    IDataObject data = Clipboard.GetDataObject();
                    if(data.GetDataPresent(DataFormats.Text))
                    {
                        _editBox.SelectedText =
                            data.GetData(DataFormats.Text).ToString();
                    }
                }
            }
        }
    }
}
